package org.teremail.smtp;

import java.util.Properties;
import java.util.concurrent.Callable;

import org.teremail.delivery.Exchange;
import org.teremail.provider.FutureProvider;
import org.teremail.service.ServiceRegistrar;

import com.google.inject.Inject;

public class SMTPServiceProvider extends FutureProvider<SMTPService> {

    @Inject
    public SMTPServiceProvider(final Exchange exchange, final Properties configuration, final ServiceRegistrar serviceRegistrar) {
        super(new Callable<SMTPService>() {
            public SMTPService call() throws Exception {
                String host = configuration.getProperty("smtp.host", "localhost");
                int port = Integer.parseInt(configuration.getProperty("smtp.port", "9025"));
                SMTPService smtpService = new SMTPService(exchange, host, port);
                smtpService.registerService(serviceRegistrar);
                
                return smtpService;
            }
        });
    }    
}
